#include "segment.h"

Segment::Segment(const char* filename, bool _rotation, short _flip, float _scale, int _x, int _y, int _ox, int _oy) {
    data = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
    threshold(data, data, 200, 255, THRESH_BINARY);
    data.convertTo(data, CV_16UC1);
    rotation = _rotation;
    flip = _flip;
    scale = _scale;
    x = _x;
    y = _y;
    ox = _ox;
    oy = _oy;
}

Mat Segment::getSegment() {
    Mat final;

    final = data;

    if (rotation) {
        transpose(data, final);
    }

    if (flip != 0) {
        cv::flip(final, final, flip);
    }

    if ((scale - 1.0f) > 0.01) {
        resize(final, final, Size(0,0), scale, scale, INTER_NEAREST);
    }

    return final;
}

void Segment::showSegment() {
    namedWindow("Segment", CV_WINDOW_AUTOSIZE);
    Mat big;
    resize(getSegment(), big, Size(0,0), 10, 10, INTER_NEAREST);
    imshow("Segment", big);
    waitKey(0);
    destroyWindow("Segment");
}

int Segment::getWidth() {
    Size s = getSegment().size();
    return s.width;
}

int Segment::getHeight() {
    Size s = getSegment().size();
    return s.height;
}
